<template>
  <div>
    <h1>人员列表</h1>
    <h3 style="color: red">calculate组件的计算总和:{{sum}}</h3>
    <input type="text" placeholder="请输入你要添加的名字" v-model="name">
    <button @click="addPersons">添加</button>
    <ul>
      <li v-for="(p,index) in persons" :key="index">{{p.name}}</li>
    </ul>
  </div>
</template>

<script>
import {nanoid} from "nanoid";
import {mapState} from "vuex";

export default {
  name: "my-person",
  data() {
    return{
      name:''
    }
  },
  computed:{
    ...mapState(['persons','sum'])
  },
  methods:{
    addPersons() {
      this.$store.commit('ADD_PERSON',{id:nanoid(),name:this.name})
    }
  }
}
</script>

<style scoped>

</style>